Skip to content

Conversation

maryam-saeidi
Copy link
Member

Closes #1591

Summary

This PR allows adding labels to the captureError function, similar to what we have in Node.js agent:
https://www.elastic.co/guide/en/apm/agent/nodejs/current/agent-api.html#apm-capture-error

Example usage:

apm.captureError(error, {
      labels: {
        errorType: 'ToastError',
      },
    });

@maryam-saeidi maryam-saeidi self-assigned this Apr 7, 2025
@maryam-saeidi maryam-saeidi marked this pull request as ready for review April 7, 2025 10:30
@maryam-saeidi maryam-saeidi requested a review from david-luna April 7, 2025 10:31
Copy link
Member

@david-luna david-luna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maryam-saeidi thanks for your contribution. In addition to my comments I think the only thing left is to update the docs. I've checked and the right place for it is in /docs/reference/agent-api.md. There is a section with the API description.

Copy link
Member

@vigneshshanmugam vigneshshanmugam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Could you also add docs for this new option as david pointed out.

@kpatticha
Copy link

@maryam-saeidi what would be the best way to test it locally?

@david-luna
Copy link
Member

david-luna commented Apr 8, 2025

There is a build error in docs unrelated to this change. However the documentation is rendered properly for the apm.captureError() API.
Link: https://docs-v3-preview.elastic.dev/elastic/apm-agent-rum-js/pull/1594/reference/agent-api#capture-error

Build error seems to be related to a cross-link refering to the APM server

Error: 'reference/ingestion-tools/observability/apm.md' is not a valid link in the 'docs-content' cross link index: https://elastic-docs-link-index.s3.us-east-2.amazonaws.com/elastic/docs-content/main/links.json
    ┌─[/github/workspace/docs/reference/index.md]
    │
 39 │ APM Agents work in conjunction with the [APM Server](docs-content://reference/ingestion-tools/observability/apm.md), [Elasticsearch](docs-content://get-started/index.md), and [Kibana](docs-content://get-started/the-stack.md). The [APM Guide](docs-content://reference/ingestion-tools/observability/apm.md) provides details on how these components work together, and provides a matrix outlining [Agent and Server compatibility](docs-content://solutions/observability/apps/apm-agent-compatibility.md).

@colleenmcginnis do you know what might be happening here? is it possible that docset.yml needs a reference to APmM server and the link needs to be changed?

The error refers to a link

APM Agents work in conjunction with the [APM Server](docs-content://reference/ingestion-tools/observability/apm.md)

but it was changed in #1592 so maybe there is caching involved?

@colleenmcginnis
Copy link
Contributor

@colleenmcginnis do you know what might be happening here? is it possible that docset.yml needs a reference to APmM server and the link needs to be changed?

It looks like this branch is two commits behind elastic:main (maryam-saeidi/apm-agent-rum-js@1591-support-labels-in-capturing-errors...elastic:apm-agent-rum-js:main) and the changes in #1592 is one of the two missing commits.

@maryam-saeidi can you catch up your branch to elastic:main to get the docs build to pass?

@maryam-saeidi
Copy link
Member Author

maryam-saeidi commented Apr 8, 2025

@maryam-saeidi what would be the best way to test it locally?

We need to build this branch and then link the package in Kibana locally.

@david-luna david-luna merged commit 3d1ce71 into elastic:main Apr 8, 2025
20 checks passed
@maryam-saeidi maryam-saeidi deleted the 1591-support-labels-in-capturing-errors branch April 8, 2025 16:26
@david-luna david-luna mentioned this pull request Apr 8, 2025
maryam-saeidi added a commit to elastic/kibana that referenced this pull request Apr 10, 2025
## Summary 

Updating apm-rum packages mostly to use this feature:
elastic/apm-agent-rum-js#1594


Changes

|Package|Previous version|Current version|Change log
([PR](https://github.com/elastic/apm-agent-rum-js/pull/1599/files))|
|---|---|---|---|
|@elastic/apm-rum|^5.16.3|^5.17.0|add support for adding labels to
captured errors
([#1594](https://github.com/elastic/apm-agent-rum-js/pull/1594))|
|@elastic/apm-rum-core|^5.22.1|^5.23.0|add support for adding labels to
captured errors
([#1594](https://github.com/elastic/apm-agent-rum-js/pull/1594))|
|@elastic/apm-rum-react|^2.0.5|^2.0.6|version bump only for package
@elastic/apm-rum-react|
maryam-saeidi added a commit to elastic/kibana that referenced this pull request Apr 15, 2025
# Backport

This will backport the following commits from `main` to `8.x`:
- [Update apm-rum packages
(#217800)](#217800)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Maryam
Saeidi","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-04-10T14:57:06Z","message":"Update
apm-rum packages (#217800)\n\n## Summary \n\nUpdating apm-rum packages
mostly to use this
feature:\nhttps://github.com/elastic/apm-agent-rum-js/pull/1594\n\n\nChanges\n\n|Package|Previous
version|Current version|Change
log\n([PR](https://github.com/elastic/apm-agent-rum-js/pull/1599/files))|\n|---|---|---|---|\n|@elastic/apm-rum|^5.16.3|^5.17.0|add
support for adding labels to\ncaptured
errors\n([#1594](https://github.com/elastic/apm-agent-rum-js/pull/1594))|\n|@elastic/apm-rum-core|^5.22.1|^5.23.0|add
support for adding labels to\ncaptured
errors\n([#1594](https://github.com/elastic/apm-agent-rum-js/pull/1594))|\n|@elastic/apm-rum-react|^2.0.5|^2.0.6|version
bump only for
package\n@elastic/apm-rum-react|","sha":"a616a40f9307cd34c6a28c7192cfee146ca5ad76","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:version","v9.1.0","v8.19.0"],"title":"Update
apm-rum
packages","number":217800,"url":"https://github.com/elastic/kibana/pull/217800","mergeCommit":{"message":"Update
apm-rum packages (#217800)\n\n## Summary \n\nUpdating apm-rum packages
mostly to use this
feature:\nhttps://github.com/elastic/apm-agent-rum-js/pull/1594\n\n\nChanges\n\n|Package|Previous
version|Current version|Change
log\n([PR](https://github.com/elastic/apm-agent-rum-js/pull/1599/files))|\n|---|---|---|---|\n|@elastic/apm-rum|^5.16.3|^5.17.0|add
support for adding labels to\ncaptured
errors\n([#1594](https://github.com/elastic/apm-agent-rum-js/pull/1594))|\n|@elastic/apm-rum-core|^5.22.1|^5.23.0|add
support for adding labels to\ncaptured
errors\n([#1594](https://github.com/elastic/apm-agent-rum-js/pull/1594))|\n|@elastic/apm-rum-react|^2.0.5|^2.0.6|version
bump only for
package\n@elastic/apm-rum-react|","sha":"a616a40f9307cd34c6a28c7192cfee146ca5ad76"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/217800","number":217800,"mergeCommit":{"message":"Update
apm-rum packages (#217800)\n\n## Summary \n\nUpdating apm-rum packages
mostly to use this
feature:\nhttps://github.com/elastic/apm-agent-rum-js/pull/1594\n\n\nChanges\n\n|Package|Previous
version|Current version|Change
log\n([PR](https://github.com/elastic/apm-agent-rum-js/pull/1599/files))|\n|---|---|---|---|\n|@elastic/apm-rum|^5.16.3|^5.17.0|add
support for adding labels to\ncaptured
errors\n([#1594](https://github.com/elastic/apm-agent-rum-js/pull/1594))|\n|@elastic/apm-rum-core|^5.22.1|^5.23.0|add
support for adding labels to\ncaptured
errors\n([#1594](https://github.com/elastic/apm-agent-rum-js/pull/1594))|\n|@elastic/apm-rum-react|^2.0.5|^2.0.6|version
bump only for
package\n@elastic/apm-rum-react|","sha":"a616a40f9307cd34c6a28c7192cfee146ca5ad76"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
maryam-saeidi added a commit to elastic/kibana that referenced this pull request Apr 15, 2025
Closes elastic/observability-dev#4022

## Summary

In this PR, we are capturing toast errors using apm-rum:


https://github.com/user-attachments/assets/b61529f9-ab8e-4171-9042-0884e11eb385


ErrorType is available in labels which this feature was added to the rum
agent in this
[PR](elastic/apm-agent-rum-js#1594).


### 🧪 How to test

Add the following to your kibana.yml file:

```
elastic.apm.active: true
elastic.apm.transactionSampleRate: 1.0
elastic.apm.environment: yourName <-- Change to your name
```
<details>
<summary>Throw a toast error</summary>

Add this code to a page as [alerts
page](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/observability/public/pages/alerts/alerts.tsx)
and visit http://localhost:5601/kibana/app/observability/alerts

```
useEffect(() => {
    const error = new Error('Mary test error > toasts.addError');
    toasts.addError(error, { title: 'Testing error toast', toastMessage: error.message });
    toasts.addDanger('Testing danger toast');
  }, []);
```

</details>

Then visit
[kibana-cloud-apm.elastic.dev](https://kibana-cloud-apm.elastic.dev/app/apm/services/kibana-frontend/errors?comparisonEnabled=true&environment=ENVIRONMENT_ALL&kuery=&latencyAggregationType=avg&offset=1d&rangeFrom=now-1h&rangeTo=now&serviceGroup=&transactionType=page-load)
filtered for `yourName` in the environment.
maryam-saeidi added a commit to maryam-saeidi/kibana that referenced this pull request Apr 17, 2025
## Summary

Updating apm-rum packages mostly to use this feature:
elastic/apm-agent-rum-js#1594

Changes

|Package|Previous version|Current version|Change log
([PR](https://github.com/elastic/apm-agent-rum-js/pull/1599/files))|
|---|---|---|---|
|@elastic/apm-rum|^5.16.3|^5.17.0|add support for adding labels to
captured errors
([elastic#1594](https://github.com/elastic/apm-agent-rum-js/pull/1594))|
|@elastic/apm-rum-core|^5.22.1|^5.23.0|add support for adding labels to
captured errors
([elastic#1594](https://github.com/elastic/apm-agent-rum-js/pull/1594))|
|@elastic/apm-rum-react|^2.0.5|^2.0.6|version bump only for package
@elastic/apm-rum-react|

(cherry picked from commit a616a40)

# Conflicts:
#	package.json
maryam-saeidi added a commit to elastic/kibana that referenced this pull request Apr 17, 2025
# Backport

This will backport the following commits from `main` to `9.0`:
- [Update apm-rum packages
(#217800)](#217800)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Maryam
Saeidi","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-04-10T14:57:06Z","message":"Update
apm-rum packages (#217800)\n\n## Summary \n\nUpdating apm-rum packages
mostly to use this
feature:\nhttps://github.com/elastic/apm-agent-rum-js/pull/1594\n\n\nChanges\n\n|Package|Previous
version|Current version|Change
log\n([PR](https://github.com/elastic/apm-agent-rum-js/pull/1599/files))|\n|---|---|---|---|\n|@elastic/apm-rum|^5.16.3|^5.17.0|add
support for adding labels to\ncaptured
errors\n([#1594](https://github.com/elastic/apm-agent-rum-js/pull/1594))|\n|@elastic/apm-rum-core|^5.22.1|^5.23.0|add
support for adding labels to\ncaptured
errors\n([#1594](https://github.com/elastic/apm-agent-rum-js/pull/1594))|\n|@elastic/apm-rum-react|^2.0.5|^2.0.6|version
bump only for
package\n@elastic/apm-rum-react|","sha":"a616a40f9307cd34c6a28c7192cfee146ca5ad76","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:version","v9.1.0","v8.19.0","v9.0.1"],"title":"Update
apm-rum
packages","number":217800,"url":"https://github.com/elastic/kibana/pull/217800","mergeCommit":{"message":"Update
apm-rum packages (#217800)\n\n## Summary \n\nUpdating apm-rum packages
mostly to use this
feature:\nhttps://github.com/elastic/apm-agent-rum-js/pull/1594\n\n\nChanges\n\n|Package|Previous
version|Current version|Change
log\n([PR](https://github.com/elastic/apm-agent-rum-js/pull/1599/files))|\n|---|---|---|---|\n|@elastic/apm-rum|^5.16.3|^5.17.0|add
support for adding labels to\ncaptured
errors\n([#1594](https://github.com/elastic/apm-agent-rum-js/pull/1594))|\n|@elastic/apm-rum-core|^5.22.1|^5.23.0|add
support for adding labels to\ncaptured
errors\n([#1594](https://github.com/elastic/apm-agent-rum-js/pull/1594))|\n|@elastic/apm-rum-react|^2.0.5|^2.0.6|version
bump only for
package\n@elastic/apm-rum-react|","sha":"a616a40f9307cd34c6a28c7192cfee146ca5ad76"}},"sourceBranch":"main","suggestedTargetBranches":["9.0"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/217800","number":217800,"mergeCommit":{"message":"Update
apm-rum packages (#217800)\n\n## Summary \n\nUpdating apm-rum packages
mostly to use this
feature:\nhttps://github.com/elastic/apm-agent-rum-js/pull/1594\n\n\nChanges\n\n|Package|Previous
version|Current version|Change
log\n([PR](https://github.com/elastic/apm-agent-rum-js/pull/1599/files))|\n|---|---|---|---|\n|@elastic/apm-rum|^5.16.3|^5.17.0|add
support for adding labels to\ncaptured
errors\n([#1594](https://github.com/elastic/apm-agent-rum-js/pull/1594))|\n|@elastic/apm-rum-core|^5.22.1|^5.23.0|add
support for adding labels to\ncaptured
errors\n([#1594](https://github.com/elastic/apm-agent-rum-js/pull/1594))|\n|@elastic/apm-rum-react|^2.0.5|^2.0.6|version
bump only for
package\n@elastic/apm-rum-react|","sha":"a616a40f9307cd34c6a28c7192cfee146ca5ad76"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/218145","number":218145,"state":"MERGED","mergeCommit":{"sha":"a32b7835a1c6a2e9aab0cf681a3fd20039eb385c","message":"[8.x]
Update apm-rum packages (#217800) (#218145)\n\n# Backport\n\nThis will
backport the following commits from `main` to `8.x`:\n- [Update apm-rum
packages\n(#217800)](https://github.com/elastic/kibana/pull/217800)\n\n\n\n###
Questions ?\nPlease refer to the [Backport
tool\ndocumentation](https://github.com/sorenlouv/backport)\n\n"}},{"branch":"9.0","label":"v9.0.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
maryam-saeidi added a commit to maryam-saeidi/kibana that referenced this pull request Apr 17, 2025
Closes elastic/observability-dev#4022

## Summary

In this PR, we are capturing toast errors using apm-rum:

https://github.com/user-attachments/assets/b61529f9-ab8e-4171-9042-0884e11eb385

ErrorType is available in labels which this feature was added to the rum
agent in this
[PR](elastic/apm-agent-rum-js#1594).

### 🧪 How to test

Add the following to your kibana.yml file:

```
elastic.apm.active: true
elastic.apm.transactionSampleRate: 1.0
elastic.apm.environment: yourName <-- Change to your name
```
<details>
<summary>Throw a toast error</summary>

Add this code to a page as [alerts
page](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/observability/public/pages/alerts/alerts.tsx)
and visit http://localhost:5601/kibana/app/observability/alerts

```
useEffect(() => {
    const error = new Error('Mary test error > toasts.addError');
    toasts.addError(error, { title: 'Testing error toast', toastMessage: error.message });
    toasts.addDanger('Testing danger toast');
  }, []);
```

</details>

Then visit
[kibana-cloud-apm.elastic.dev](https://kibana-cloud-apm.elastic.dev/app/apm/services/kibana-frontend/errors?comparisonEnabled=true&environment=ENVIRONMENT_ALL&kuery=&latencyAggregationType=avg&offset=1d&rangeFrom=now-1h&rangeTo=now&serviceGroup=&transactionType=page-load)
filtered for `yourName` in the environment.

(cherry picked from commit ae9e5d6)

# Conflicts:
#	src/core/packages/notifications/browser-internal/src/toasts/toasts_api.tsx
maryam-saeidi added a commit to elastic/kibana that referenced this pull request Apr 29, 2025
Closes elastic/observability-dev#4463

## Summary

Since we now have support for error labels in RUM
([PR](elastic/apm-agent-rum-js#1594)), this PR
changes the way that we report rum errors to use labels similar to what
we've done for toast errors
([PR](#217948)).



https://github.com/user-attachments/assets/87a06ceb-705c-4c6e-ab26-d3e5874fe5ad


### ⚠️ Note

In local development, the error is captured twice because react bubbles
up the error, but it does not happen in production:
([doc](https://react.dev/reference/react/Component#componentdidcatch-caveats))

> Production and development builds of React slightly differ in the way
componentDidCatch handles errors. In development, the errors will bubble
up to window, which means that any window.onerror or
window.addEventListener('error', callback) will intercept the errors
that have been caught by componentDidCatch. In production, instead, the
errors will not bubble up, which means any ancestor error handler will
only receive errors not explicitly caught by componentDidCatch.

### 🧪 How to test

Add the following to your kibana.yml file:

```
elastic.apm.active: true
elastic.apm.transactionSampleRate: 1.0
elastic.apm.environment: yourName <-- Change to your name
```
<details>
<summary>Throw a fatal react error</summary>

Throw an error in the [alerts
page](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/observability/public/pages/alerts/alerts.tsx)
and visit http://localhost:5601/kibana/app/observability/alerts

</details>

Then visit
[kibana-cloud-apm.elastic.dev](https://kibana-cloud-apm.elastic.dev/app/apm/services/kibana-frontend/errors?comparisonEnabled=true&environment=ENVIRONMENT_ALL&kuery=&latencyAggregationType=avg&offset=1d&rangeFrom=now-1h&rangeTo=now&serviceGroup=&transactionType=page-load)
filtered for `yourName` in the environment.
akowalska622 pushed a commit to akowalska622/kibana that referenced this pull request May 29, 2025
Closes elastic/observability-dev#4463

## Summary

Since we now have support for error labels in RUM
([PR](elastic/apm-agent-rum-js#1594)), this PR
changes the way that we report rum errors to use labels similar to what
we've done for toast errors
([PR](elastic#217948)).



https://github.com/user-attachments/assets/87a06ceb-705c-4c6e-ab26-d3e5874fe5ad


### ⚠️ Note

In local development, the error is captured twice because react bubbles
up the error, but it does not happen in production:
([doc](https://react.dev/reference/react/Component#componentdidcatch-caveats))

> Production and development builds of React slightly differ in the way
componentDidCatch handles errors. In development, the errors will bubble
up to window, which means that any window.onerror or
window.addEventListener('error', callback) will intercept the errors
that have been caught by componentDidCatch. In production, instead, the
errors will not bubble up, which means any ancestor error handler will
only receive errors not explicitly caught by componentDidCatch.

### 🧪 How to test

Add the following to your kibana.yml file:

```
elastic.apm.active: true
elastic.apm.transactionSampleRate: 1.0
elastic.apm.environment: yourName <-- Change to your name
```
<details>
<summary>Throw a fatal react error</summary>

Throw an error in the [alerts
page](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/observability/public/pages/alerts/alerts.tsx)
and visit http://localhost:5601/kibana/app/observability/alerts

</details>

Then visit
[kibana-cloud-apm.elastic.dev](https://kibana-cloud-apm.elastic.dev/app/apm/services/kibana-frontend/errors?comparisonEnabled=true&environment=ENVIRONMENT_ALL&kuery=&latencyAggregationType=avg&offset=1d&rangeFrom=now-1h&rangeTo=now&serviceGroup=&transactionType=page-load)
filtered for `yourName` in the environment.
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jun 2, 2025
Closes elastic/observability-dev#4463

## Summary

Since we now have support for error labels in RUM
([PR](elastic/apm-agent-rum-js#1594)), this PR
changes the way that we report rum errors to use labels similar to what
we've done for toast errors
([PR](elastic#217948)).

https://github.com/user-attachments/assets/87a06ceb-705c-4c6e-ab26-d3e5874fe5ad

### ⚠️ Note

In local development, the error is captured twice because react bubbles
up the error, but it does not happen in production:
([doc](https://react.dev/reference/react/Component#componentdidcatch-caveats))

> Production and development builds of React slightly differ in the way
componentDidCatch handles errors. In development, the errors will bubble
up to window, which means that any window.onerror or
window.addEventListener('error', callback) will intercept the errors
that have been caught by componentDidCatch. In production, instead, the
errors will not bubble up, which means any ancestor error handler will
only receive errors not explicitly caught by componentDidCatch.

### 🧪 How to test

Add the following to your kibana.yml file:

```
elastic.apm.active: true
elastic.apm.transactionSampleRate: 1.0
elastic.apm.environment: yourName <-- Change to your name
```
<details>
<summary>Throw a fatal react error</summary>

Throw an error in the [alerts
page](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/observability/public/pages/alerts/alerts.tsx)
and visit http://localhost:5601/kibana/app/observability/alerts

</details>

Then visit
[kibana-cloud-apm.elastic.dev](https://kibana-cloud-apm.elastic.dev/app/apm/services/kibana-frontend/errors?comparisonEnabled=true&environment=ENVIRONMENT_ALL&kuery=&latencyAggregationType=avg&offset=1d&rangeFrom=now-1h&rangeTo=now&serviceGroup=&transactionType=page-load)
filtered for `yourName` in the environment.

(cherry picked from commit cea253d)
kibanamachine added a commit to elastic/kibana that referenced this pull request Jun 2, 2025
# Backport

This will backport the following commits from `main` to `8.19`:
- [Use RUM label for fatal react errors
(#218846)](#218846)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Maryam
Saeidi","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-04-29T08:14:48Z","message":"Use
RUM label for fatal react errors (#218846)\n\nCloses
https://github.com/elastic/observability-dev/issues/4463\n\n##
Summary\n\nSince we now have support for error labels in
RUM\n([PR](elastic/apm-agent-rum-js#1594)), this
PR\nchanges the way that we report rum errors to use labels similar to
what\nwe've done for toast
errors\n([PR](https://github.com/elastic/kibana/pull/217948)).\n\n\n\nhttps://github.com/user-attachments/assets/87a06ceb-705c-4c6e-ab26-d3e5874fe5ad\n\n\n###
⚠️ Note\n\nIn local development, the error is captured twice because
react bubbles\nup the error, but it does not happen in
production:\n([doc](https://react.dev/reference/react/Component#componentdidcatch-caveats))\n\n>
Production and development builds of React slightly differ in the
way\ncomponentDidCatch handles errors. In development, the errors will
bubble\nup to window, which means that any window.onerror
or\nwindow.addEventListener('error', callback) will intercept the
errors\nthat have been caught by componentDidCatch. In production,
instead, the\nerrors will not bubble up, which means any ancestor error
handler will\nonly receive errors not explicitly caught by
componentDidCatch.\n\n### 🧪 How to test\n\nAdd the following to your
kibana.yml file:\n\n```\nelastic.apm.active:
true\nelastic.apm.transactionSampleRate: 1.0\nelastic.apm.environment:
yourName <-- Change to your name\n```\n<details>\n<summary>Throw a fatal
react error</summary>\n\nThrow an error in the
[alerts\npage](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/observability/public/pages/alerts/alerts.tsx)\nand
visit
http://localhost:5601/kibana/app/observability/alerts\n\n</details>\n\nThen
visit\n[kibana-cloud-apm.elastic.dev](https://kibana-cloud-apm.elastic.dev/app/apm/services/kibana-frontend/errors?comparisonEnabled=true&environment=ENVIRONMENT_ALL&kuery=&latencyAggregationType=avg&offset=1d&rangeFrom=now-1h&rangeTo=now&serviceGroup=&transactionType=page-load)\nfiltered
for `yourName` in the
environment.","sha":"cea253dcc67ed2cfb460a0707ac1e66cdb9180fa","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:version","v9.1.0","v8.19.0"],"title":"Use
RUM label for fatal react
errors","number":218846,"url":"https://github.com/elastic/kibana/pull/218846","mergeCommit":{"message":"Use
RUM label for fatal react errors (#218846)\n\nCloses
https://github.com/elastic/observability-dev/issues/4463\n\n##
Summary\n\nSince we now have support for error labels in
RUM\n([PR](elastic/apm-agent-rum-js#1594)), this
PR\nchanges the way that we report rum errors to use labels similar to
what\nwe've done for toast
errors\n([PR](https://github.com/elastic/kibana/pull/217948)).\n\n\n\nhttps://github.com/user-attachments/assets/87a06ceb-705c-4c6e-ab26-d3e5874fe5ad\n\n\n###
⚠️ Note\n\nIn local development, the error is captured twice because
react bubbles\nup the error, but it does not happen in
production:\n([doc](https://react.dev/reference/react/Component#componentdidcatch-caveats))\n\n>
Production and development builds of React slightly differ in the
way\ncomponentDidCatch handles errors. In development, the errors will
bubble\nup to window, which means that any window.onerror
or\nwindow.addEventListener('error', callback) will intercept the
errors\nthat have been caught by componentDidCatch. In production,
instead, the\nerrors will not bubble up, which means any ancestor error
handler will\nonly receive errors not explicitly caught by
componentDidCatch.\n\n### 🧪 How to test\n\nAdd the following to your
kibana.yml file:\n\n```\nelastic.apm.active:
true\nelastic.apm.transactionSampleRate: 1.0\nelastic.apm.environment:
yourName <-- Change to your name\n```\n<details>\n<summary>Throw a fatal
react error</summary>\n\nThrow an error in the
[alerts\npage](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/observability/public/pages/alerts/alerts.tsx)\nand
visit
http://localhost:5601/kibana/app/observability/alerts\n\n</details>\n\nThen
visit\n[kibana-cloud-apm.elastic.dev](https://kibana-cloud-apm.elastic.dev/app/apm/services/kibana-frontend/errors?comparisonEnabled=true&environment=ENVIRONMENT_ALL&kuery=&latencyAggregationType=avg&offset=1d&rangeFrom=now-1h&rangeTo=now&serviceGroup=&transactionType=page-load)\nfiltered
for `yourName` in the
environment.","sha":"cea253dcc67ed2cfb460a0707ac1e66cdb9180fa"}},"sourceBranch":"main","suggestedTargetBranches":["8.19"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/218846","number":218846,"mergeCommit":{"message":"Use
RUM label for fatal react errors (#218846)\n\nCloses
https://github.com/elastic/observability-dev/issues/4463\n\n##
Summary\n\nSince we now have support for error labels in
RUM\n([PR](elastic/apm-agent-rum-js#1594)), this
PR\nchanges the way that we report rum errors to use labels similar to
what\nwe've done for toast
errors\n([PR](https://github.com/elastic/kibana/pull/217948)).\n\n\n\nhttps://github.com/user-attachments/assets/87a06ceb-705c-4c6e-ab26-d3e5874fe5ad\n\n\n###
⚠️ Note\n\nIn local development, the error is captured twice because
react bubbles\nup the error, but it does not happen in
production:\n([doc](https://react.dev/reference/react/Component#componentdidcatch-caveats))\n\n>
Production and development builds of React slightly differ in the
way\ncomponentDidCatch handles errors. In development, the errors will
bubble\nup to window, which means that any window.onerror
or\nwindow.addEventListener('error', callback) will intercept the
errors\nthat have been caught by componentDidCatch. In production,
instead, the\nerrors will not bubble up, which means any ancestor error
handler will\nonly receive errors not explicitly caught by
componentDidCatch.\n\n### 🧪 How to test\n\nAdd the following to your
kibana.yml file:\n\n```\nelastic.apm.active:
true\nelastic.apm.transactionSampleRate: 1.0\nelastic.apm.environment:
yourName <-- Change to your name\n```\n<details>\n<summary>Throw a fatal
react error</summary>\n\nThrow an error in the
[alerts\npage](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/observability/public/pages/alerts/alerts.tsx)\nand
visit
http://localhost:5601/kibana/app/observability/alerts\n\n</details>\n\nThen
visit\n[kibana-cloud-apm.elastic.dev](https://kibana-cloud-apm.elastic.dev/app/apm/services/kibana-frontend/errors?comparisonEnabled=true&environment=ENVIRONMENT_ALL&kuery=&latencyAggregationType=avg&offset=1d&rangeFrom=now-1h&rangeTo=now&serviceGroup=&transactionType=page-load)\nfiltered
for `yourName` in the
environment.","sha":"cea253dcc67ed2cfb460a0707ac1e66cdb9180fa"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Maryam Saeidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for adding labels to error logs

5 participants